<?php
/**
 * 申请报单中心
 *
 *
 *
 * * @网店运维 (c) 2015-2018 ShopWWI Inc. (http://www.shopwwi.com)
 * @license    http://www.shopwwi.c om
 * @link       交流群号：111731672
 * @since      网店运维提供技术支持 授权请购买shopnc授权
 */
defined('ByShopWWI') or exit('Access Invalid!');
class apply_formModel extends Model {
    
     public function __construct() {
        parent::__construct('apply_form');
    }
    /**
     * 获取申请列表
     * @param type $condition
     * @param type $page
     * @param type $order
     * @param type $field
     * @param type $limit
     * @return type
     */
    
      public function getApplyList($condition, $page = null, $order = 'apply_form_id asc', $field = '*', $limit = 0) {
        return $this->field($field)->where($condition)->page($page)->order($order)->limit($limit)->select();
    }
    
     /**
     * 申请详细信息（查库）
     * @param array $condition
     * @param string $field
     * @return array
     */
    public function getApplyInfo($condition, $field = '*') {
        return $this->field($field)->where($condition)->find();
    }
    /*
     * 提交申请
     * @param array $param
     * @return bool
     *
     */
    public function addApply($param){
       
        $param['apply_time']=time();
     

        $condition= array('member_id'=>$_SESSION['member_id'],'status'=>array('in','0,1'));
        $applyList=$this->where($condition)->select();
        if(is_array($applyList)&&!empty($applyList))
        {
            return false;
        }
       
        $result = $this->insert($param);
        if ($result) {
            return $result;
        } else {
            return false;
        }
    }
    
     /**
     * 编辑申请
     * @param array $condition
     * @param array $data
     */
    public function editApply($condition, $data) {

        $update = $this->where($condition)->update($data);
        return $update;
    }

    
    /**
     * 申请数量
     * @param array $condition
     * @return int
     */
    public function getApplyCount($condition) {
        return $this->where($condition)->count();
    }
}
